<span page-title ng-model="host">{{ 'Errata for: ' | translate }} {{ host.name }}</span>

<div bst-feature-flag="remote_actions">
  <h3 translate ng-hide="selectedErrataOption === 'current'">Applicable Errata</h3>
  <h3 translate ng-show="selectedErrataOption === 'current'">Installable Errata</h3>
</div>

<div ng-show="katelloAgentPresent" data-extend-template="common/views/katello-agent-notice.html"></div>

<div ng-hide="host.hasContent()">
  <div data-extend-template="common/views/registration.html"></div>
</div>

<div ng-if="host && host.hasContent()">
  <div data-block="messages" ng-show="table.rows.length > 0">
    <p bst-alert="info" ng-hide="selectedErrataOption === 'current'">
      <span translate>
        Some of the Errata shown below may not be installable as they are not in this Content Host's
        Content View and Lifecycle Environment.  In order to apply such Errata an Incremental Update is required.
      </span>

      <a ui-sref="errata" translate>Click here to select Errata for an Incremental Update.</a>
    </p>
  </div>

  <div bst-feature-flag="remote_actions">
    <p bst-alert="warning" ng-hide="hostToolingEnabled">
      <span translate>
        Performing host package actions is disabled because Katello is not configured for Remote Execution or Katello Agent.
        </span>
    </p>
  </div>

  <form id="errataActionForm" method="post" action="/katello/remote_execution">
    <input type="hidden" name="remote_action" value="errata_install"/>
    <input type="hidden" name="name" ng-value="errataActionFormValues.errata"/>
    <input type="hidden" name="bulk_host_ids" ng-value="errataActionFormValues.bulkHostIds"/>
    <input type="hidden" name="bulk_errata_ids" ng-value="errataActionFormValues.bulkErrataIds"/>
    <input type="hidden" name="customize" ng-value="errataActionFormValues.customize"/>
    <input type="hidden" name="authenticity_token" ng-value="errataActionFormValues.authenticityToken"/>
  </form>

  <div data-extend-template="layouts/partials/table.html">
    <span data-block="search-filter" bst-feature-flag="remote_actions">
      <label class="sr-only" translate>
        Limit to environment
      </label>
      <select class="form-control"
              placeholder="{{ 'Limit to Lifecycle Environment' | translate }}"
              ng-model="selectedErrataOption"
              ng-change="refreshErrata(selectedErrataOption)"
              ng-options="option.label as option.name for option in errataOptions | orderBy: 'order'">
      </select>
    </span>

    <span data-block="list-actions" ng-hide="contentHost.readonly">
      <div bst-modal="applySelected()" model="host">
        <div data-block="modal-header" translate>Apply Errata to Content Host "{{host.name}}"?</div>
        <div data-block="modal-body" translate>Are you sure you want to apply Errata to content host "{{ host.name }}"?</div>
        <span data-block="modal-confirm-button">
          <button class="btn btn-primary" ng-click="ok()">
            <span translate>Apply</span>
          </button>
        </span>
      </div>

        <span bst-feature-flag="remote_actions">
          <span uib-dropdown class="btn-group">
            <button class="btn btn-default" type="button"
                    translate
                    ng-hide="denied('edit_hosts', host)"
                    ng-disabled="table.getSelected().length == 0 || !hostToolingEnabled"
                    ng-click="openModal()">
              Apply Selected
            </button>
            <button uib-dropdown-toggle class="btn btn-primary"
                    ng-hide="!remoteExecutionPresent || denied('edit_hosts', host)"
                    ng-disabled="table.getSelected().length == 0"
                    type="button" id="use-remote-execution">
              <span class="caret"></span>
            </button>
            <ul uib-dropdown-menu role="menu" aria-labelledby="use-remote-execution">
              <li ng-show="katelloAgentPresent" role="presentation"><a ng-click="performViaKatelloAgent()" role="menuitem" tabindex="-1" href="#" translate>via Katello agent</a></li>
              <li role="presentation"><a ng-click="performViaRemoteExecution(false)" role="menuitem" tabindex="-1" href="#" translate>via remote execution</a></li>
              <li role="presentation"><a ng-click="performViaRemoteExecution(true)" role="menuitem" tabindex="-1" href="#" translate>via remote execution - customize first</a></li>
            </ul>
          </span>
        </span>
        <button class="btn btn-default" type="button"
                translate
                ng-hide="denied('edit_hosts', host)"
                ng-disabled="calculatingApplicability"
                ng-click="calculateApplicability()">
          Recalculate
          <i class="fa fa-spinner fa-spin" ng-show="calculatingApplicability"></i>
        </button>
    </span>

    <span data-block="no-rows-message" translate>
      There are no Errata to display.
    </span>

    <span data-block="no-search-results-message" translate>
      Your search returned zero Errata.
    </span>

    <div data-block="table">
      <table class="table table-striped table-bordered" ng-class="{'table-mask': table.working}">
        <thead>
          <tr bst-table-head row-select>
            <th bst-table-column="type" translate>Type</th>
            <th bst-table-column="errata_id" translate>Id</th>
            <th bst-table-column="title" translate>Title</th>
            <th bst-table-column="issued" translate>Issued</th>
          </tr>
        </thead>
        <div data-extend-template="layouts/select-all-results.html"></div>
        <tbody>
          <tr bst-table-row ng-repeat="erratum in table.rows | filter:table.errataCompare" row-select="erratum">
            <td bst-table-cell>
                <span ng-show="erratum.type == 'security'">
                  <i class="fa fa-warning inline-icon" title="{{ 'Security' | translate }}"></i>
                </span>

                <span ng-show="erratum.type == 'bugfix' || erratum.type == 'recommended'">
                  <i class="fa fa-bug inline-icon" title="{{ 'Bug Fix' | translate }}"></i>
                </span>

                <span ng-show="erratum.type == 'enhancement' || erratum.type == 'optional'">
                  <i class="fa fa-plus-square inline-icon" title="{{ 'Enhancement' | translate }}"></i>
                </span>

              {{ erratum.type | errataType}}
              <span ng-show="erratum.severity">- {{ erratum.severity | errataSeverity}}</span>
            </td>
            <td bst-table-cell >
              <a ng-click="transitionToErratum(erratum)">
                {{ erratum.errata_id }}
              </a>
            </td>
            <td bst-table-cell>{{ erratum.title }}</td>
            <td bst-table-cell><date date="erratum.updated" /></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>
